package com.peitamerchants.ui.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.peitamerchants.R;
import com.peitamerchants.ui.fragment.LogFragment;
import com.peitamerchants.ui.fragment.MessageFragment;
import com.peitamerchants.ui.fragment.MyFragment;
import com.peitamerchants.ui.fragment.ShopFragment;
import com.peitamerchants.ui.fragment.adapter.FragmentAdapter;

import java.util.ArrayList;
import java.util.List;

import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.PageBottomTabLayout;

/**
 * Created by zy on 2017/5/12.
 */

public class HomeActivity extends AppCompatActivity{
    private ViewPager vp;
    private List<Fragment> fragments;
    private PageBottomTabLayout pbtable;
    private NavigationController mNavigationController;
    private FragmentAdapter fragmentAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initView();
        initData();
    }

    private void initData() {
        mNavigationController = pbtable.material()
                .addItem(R.drawable.icon_dianpu, "店铺")
                .addItem(R.drawable.icon_xiaoxi, "消息")
                .addItem(R.drawable.icon_rizhi, "日志")
                .addItem(R.drawable.icon_wode, "我的")
                .setDefaultColor(0x89FFFFFF)//未选中状态的颜色
                .build();

        fragments = new ArrayList<>();
        fragments.add(new ShopFragment());
        fragments.add(new MessageFragment());
        fragments.add(new LogFragment());
        fragments.add(new MyFragment());
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
        vp.setAdapter(fragmentAdapter);

        mNavigationController.setupWithViewPager(vp);
    }

    private void initView() {
        vp = (ViewPager) findViewById(R.id.home_viewpage);
        pbtable = (PageBottomTabLayout) findViewById(R.id.home_pbtable);
    }
}
